﻿<%@ WebHandler Language="C#" Class="collect" %>

using System;
using System.Web;
using System.Web.SessionState;


using App_Code.PublicHelper;

public class collect : IHttpHandler, IRequiresSessionState {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "application/json";

        //首先判断是否登录
        if (!UserHelper.IsLogin())
        {
            context.Response.Write("{\"collect\":false,\"data\":{\"isLogin\":false}}");
            return;
        }

        string id = context.Request.QueryString["id"];
        if (string.IsNullOrEmpty(id))
        {
            context.Response.Write("{\"collect\":false,\"data\":{\"info\":\"错误的请求\"}}");
            return;
        }

        if (DataHelper.IsCollect(int.Parse(id), UserHelper.GetCurrentUser().ID))
        {
            context.Response.Write("{\"collect\":false,\"data\":{\"info\":\"该数据已收藏\"}}");
            return;
        }

        DataHelper.collect(int.Parse(id), UserHelper.GetCurrentUser().ID);
        context.Response.Write("{\"collect\":true,\"data\":{\"info\":\"数据收藏成功\"}}");
        return;
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}